package com.alan.api.util;


import com.alan.server.bean.UserVO;

/**
 * Created by Alan on 2017/11/3.
 */
public class UserUtils {

    private static RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);

    public static UserVO getUserVo(){
        String tokenId = Mvc2Utils.getParameter(TokenUtils.TOKEN);
        UserVO userVO = redisUtils.getObject(tokenId,UserVO.class);
        return userVO;
    }

    public static UserVO getUserVo(boolean isRefresh){
        String tokenId = Mvc2Utils.getParameter(TokenUtils.TOKEN);
        UserVO userVO = redisUtils.getObject(tokenId,UserVO.class);
        //TODO refresh userVo

        return userVO;
    }

    public static void setUserVo(UserVO userVo){
        String tokenId = Mvc2Utils.getParameter(TokenUtils.TOKEN);
        redisUtils.setObject(tokenId,userVo,60*30L);
    }

    public static void loginOut(){
        redisUtils.del( getUserVo().getId().toString());
        redisUtils.del( TokenUtils.getTokenId() );
    }


}
